PHP automatically loads autoload and namespace application summary, autoload namespace
Let's talk about what a namespace is.
"What is a namespace? In a broad sense, namespace is a way to encapsulate things. This abstract concept can be seen in many
PHP namespace and automatic loading class, PHP namespace loading class. PHP namespaces and automatic loading classes. PHP namespaces are only available after php5.3. This concept has been available in C # for a long time. namesp php namespace and
This article introduces the content of the PHP surface of the question four implementation autoload, has a certain reference value, now share to everyone, the need for friends can refer to
The YII framework declares its own class-loading method to
PHP namespace and automatic loading class, PHP namespace loading class
PHP namespace is available only after php5.3. This concept has been available in C # for a long time. The namespace in php is actually the same as that in c.
Why use namespace in
Suppose one of the directories of my project:
app== site==== controller====== IndexController.php====== AccessController.php== api==== controller====== PostController.php
Suppose the content of indexcontroller.php:
namespace
PHP dependency management tool Composer autoload and dependencyautoload
For example, if our project wants to use the monolog log tool, we need to tell composer in composer. json that we need it:
{ "require": { "monolog/monolog": "1.*" }}
Then
[PHP] _ autoload () magic method and spl_autoload_register, splregisterautoload
Reference link:
1. Details about the differences between spl_autoload_register and autoload
2. php.net automatic loading class
Many developers create a PHP source file
PHP Namespaces and Auto-load classes, PHP namespace loading classes
PHP's namespace (namespace) is only available after php5.3. This concept is already very early in C #, and the namespace in PHP is actually the same as the C # concept.
Why should
Before using namespace for autoloading to introduce PSR-0, let's talk about NameSpace and Autoloading.
NameSpace)
Namespace is a new feature added to PHP5.3. it is used to solve the two problems encountered when you create reusable code such as
New namespace rule parsing and advanced functions in PHP5.3. In PHP5.3, the most important new feature is the addition of namespaces. This article introduces some terms of the PHP namespace, its parsing rules, and some advanced features of the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.